package TRSS
import (
    "fmt"
    "bufio"
    "os"
    "io/ioutil"
    "strings"

)
//这里是TRSS公共结构体
type token struct {
	Tips []string `yaml:"tips"`
	Token []string `yaml:"token"`
    permission []string `yaml:"permission"`
}
type Admin struct {
    AutoFriend    int      `yaml:"autoFriend"`
    AutoQuit      int      `yaml:"autoQuit"`
    MasterQQ      []string  `yaml:"masterQQ"`
    Master        []string `yaml:"master"`
    DisablePrivate bool     `yaml:"disablePrivate"`
    DisableMsg    string   `yaml:"disableMsg"`
    DisableAdopt  []string `yaml:"disableAdopt"`
    WhiteGroup    []string `yaml:"whiteGroup"`
    BlackGroup    []int    `yaml:"blackGroup"`
    BlackQQ       []int    `yaml:"blackQQ"`
}

type Plugin struct {
	ID          string
	Name        string
	Description string
	Path        string
	git         string
	depend      string
}



//文件操作
// 读取文件
func readFile(path string) ([]byte, error) {
    file, err := os.Open(path)
    if err != nil {
        return nil, fmt.Errorf("打开文件失败：%v", err)
    }
    defer file.Close()

    data, err := ioutil.ReadAll(file)
    if err != nil {
        return nil, fmt.Errorf("读取文件失败：%v", err)
    }

    return data, nil
}

// 写入文件
func writeFile(path, content string) error {
    file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0644)
    if err != nil {
        return fmt.Errorf("打开文件失败：%v", err)
    }
    defer file.Close()

    writer := bufio.NewWriter(file)
    defer writer.Flush()

    _, err = writer.WriteString(content)
    if err != nil {
        return fmt.Errorf("写入文件失败：%v", err)
    }

    return nil
}
//连接符前面加空格
func addSpaceBeforeHyphen(yamlData string) string {
	lines := strings.Split(yamlData, "\n")
	for i, line := range lines {
		if strings.Contains(line, "-") && !strings.HasPrefix(line, " -") {
			lines[i] = strings.Replace(line, "-", "  -", 1)
		}
	}
	return strings.Join(lines, "\n")
}


